import { createStore } from 'vuex'

const store = createStore({
  state: {
    isCollapse: true,
    active: sessionStorage.getItem('path') || '/home/index',

    //权限需求
    quanxian: false,

    //面包屑的当前值
    currentMenu: {
      name: '',
      path: '',
    },
    Menu: null,
    // 点击首页的时候让菜单消失
    showClick: true,
    //点击菜单的时候,让子菜单消失
    ziCaiDanShow: true,
  },

  mutations: {
    changeCollapse(state, payload) {
      state.isCollapse = !state.isCollapse
    },

    changeId(state, payload) {
      state.id = payload
      // console.log(state.id)
    },
    //登录账号权限问题
    changeQuanXian(state, payload) {
      if (localStorage.getItem('user')) {
        let res = JSON.parse(localStorage.getItem('user'))
        if (res.username == 'rong') {
          state.quanxian = true
        }
      }
    },
    //面包屑的selectMenu
    selectMenu(state, val) {
      // console.log(val)
      val.name == '首页' ? (state.currentMenu = null) : (state.currentMenu.name = val.name)
      Object.assign(state.currentMenu, val)
      // console.log(state.currentMenu)
    },
    //主菜单
    Menu(state, val) {
      val == '首页' ? (state.Menu = null) : (state.Menu = val)
    },
  },
})

export default store
